lexer grammar AnalizadorC;

options {
  language = Java;
}




@lexer::header{package PL.practica4vs2;}
@lexer::members {
public class MyToken extends CommonToken {
    String nFile; // custom field
    public MyToken(CharStream input, int type, int channel, int start, int stop){
        super(input, type, channel, start, stop);
        nFile = "";
    }
    public void getNfile (String s){nFile= s;}
    public String setNfile (){return nFile;}
    public String toString() { return super.toString()+",nombre fichero="+nFile; }
}

ArrayList <RecognitionException> errores = new ArrayList<RecognitionException>();

public boolean listaVacia (){
    if (errores.isEmpty()){
      return true;
    }else
      return false;
}

public ArrayList getListaErrores(){return errores;}

@Override
public void reportError (RecognitionException e){
  errores.add(e);
}
 
// override standard token emission
public Token emit() {
    MyToken t =
        new MyToken(input, state.type, state.channel,
                    state.tokenStartCharIndex, getCharIndex()-1);
    t.setLine(state.tokenStartLine);
    t.setText(state.text);
    t.setCharPositionInLine(state.tokenStartCharPositionInLine);
    t.nFile = this.getSourceName();
    emit(t);
    return t;
}
}
 
  VOID : 'void';
  INT : 'int'; 
  WHILE : 'while';
  IF :  'if';
  fragment NUEVA_LINEA: '\r\n' ;
  fragment LETRA : ('a'..'z')|'_';
  BLANCO: (' '|'\t'|NUEVA_LINEA) {skip();};
  fragment DIGITO: '0'..'9';
  NUMERO: (DIGITO)+('.'(DIGITO)+)?;
  LLAVES : '{'|'}';
  OPERADOR: '+'|'-'|'/'|'*';
  PARENTESIS: '('|')';
  SEPARADOR: ';';
  COMENTARIO: '/*' ('*' ~('/')| ~ ('*'))* '*/'{skip();};
  COMENTARIOlINEA : '//' (options {greedy=false;}:.)* NUEVA_LINEA {skip();};
  CADENA : '"' (options {greedy=false;}:.)* '"';
  IDENT : LETRA(LETRA|DIGITO)*;
  IDENTP : '&'LETRA(LETRA|DIGITO)*;
  ANGULO : '<'|'>';
  COMA : ',';
  IGUAL : '=';
